package cn.edu.zut.internship.utils;

import java.util.Calendar;
import java.util.Date;

public class FileNameUtil {
    /**
     * 生成随机文件后部名称
     * @return
     */
    public static String getFileName(){
        //生成日期的字符串
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH);
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        //补两位,因为一年最多三位数
        String monthFormat = String.format("%1$02d", month+1);
        //补两位，因为日最多两位数
        String dayFormat = String.format("%1$02d", day);
        //补两位，因为小时最多两位数
        String hourFormat = String.format("%1$02d", hour);
        return year + monthFormat + dayFormat+hourFormat+"_"+Math.round((Math.random()+1) * 1000);
    }
}
